/*
PORN-OS API
The one and only way to request services from the kernel
*/

#ifndef API_H
#define API_H

#include "types.h"
#include "null.h"
#include "message.h"
#include "process_supervision.h"

/* creates a new process executing the program progname and returns its pid (or -1 in case of failure. Up to four parameters can be passed to the new process using the parameters array. */
int32_t fourchette(int32_t priority, char * progname, int32_t parameters[4]);

/* kills the process pid and transmits the exit_code to its supervisors (if any) */
int32_t tuer(int32_t pid, int32_t exit_code);

/* the caller is removed from the system and exit_code is returned to its supervisors (if any) */
void quitter(int32_t exit_code);

/* changes the priority of the process pid by priority */
int32_t changer_priorite(int32_t pid, int32_t priority);

/* returns the program name (up to n characters) being executed by the process pid */
int32_t obtenir_programme(int32_t pid, char* progname, int32_t n);

/* returns the pid of the current process (or -1 in case of failure) */
int32_t obtenir_pid();

/* returns the priority of the process pid or -1 in case of failure */
int32_t obtenir_priorite(int32_t pid);

/* returns the state of the process pid or -1 in case of failure */
int32_t obtenir_etat(int32_t pid);

/* returns the parent's pid of the process pid or -2 in case of failure */
int32_t obtenir_parent(int32_t pid);

/* returns the list of the pids of all the processes in the system */
int32_t obtenir_tous_pid(int32_t * pid_list);

/* prints string using tty0. Returns 1 in case of success and 0 otherwise.*/
int32_t ecrire(const char* data);

/* prints string to the LCD. Returns 1 in case of success and 0 otherwise.*/
int32_t ecrire_lcd(const char* data);

int obtenir_temps(int* time);

/* reads data from the user (up to length-1 characters or until a \r character is entered. Returns 1 if success, O otherwise. Adds the \0 at the end of the result. */
int32_t lire(char* data, int length);

/* blocks the process pid until it is waken up using reveiller()*/
int32_t bloquer(int32_t pid);

/* the caller waits for the process pid to terminate. Returns 1 if the call is a success, 0 otherwise. pid must be the pid of a caller's child. The return value given by the process pid at termination is transmitted to the caller using the parameter return_value. */
int32_t attendre(int32_t pid, int32_t* status);

/* wakes a blocked process up. It only affects processes blocked (and not delayed) */
int32_t reveiller(int32_t pid);

/* delays the process pid for n ms */
int32_t retarder(int32_t pid, uint32_t n);

/* allocates size bytes and returns a pointer to them */
void* allouer(int32_t size);

/* frees the memory pointed by pointer */
int32_t liberer(void* pointer);

/* sends a message containing a string */
int32_t envoyer_chaine(int32_t to, char* data, int32_t priority);

/* sends a message containing an integer */
int32_t envoyer_entier(int32_t to, int32_t data, int32_t priority);

/* receives the first message of the message queue (or waits until one arrives).Returns 1 if a message has been read, 0 in case of error. */
int32_t recevoir_premier(message* message);

/* receives the first message from the process from (or waits until one arrives). Returns 1 if a message has been read, 0 in case of error. */
int32_t recevoir_destinataire(int32_t from, message* message);

/* receives the first message with the correct priority (or waits until one arrives). Returns 1 if a message has been read, 0 in case of error. */
int32_t recevoir_priorite(int32_t priority, message* message);

/* receives the first message of the message queue (or waits until either one arrives or the specified time is up). Returns 1 if a message has been read, 0 in case of error.*/
int32_t recevoir_premier_delai(message* message, uint32_t timeout);

/* receives the first message from the process from (or waits until either one arrives or the specified time is up). Returns 1 if a message has been read, 0 in case of error. */
int32_t recevoir_destinataire_delai(int32_t from, message* message, uint32_t timeout);

/* receives the first message with the correct priority (or waits until either one arrives or the specified time is up). Returns 1 if a message has been read, 0 in case of error. */
int32_t recevoir_priorite_delai(int32_t priority, message* message, uint32_t timeout);

/* returns the number of messages the caller has in its message queue */
int32_t obtenir_nombre_messages();

/* registers the caller as a supervisor of supervised_pid */
int32_t superviser(int32_t supervised_pid);

#endif
